import { ref, onMounted } from "vue";
import { useRoute, onBeforeRouteUpdate } from "vue-router";

export default function useParam(cb: Function) {
    const route = useRoute();
    const param = ref(route.params.type);

    onBeforeRouteUpdate((props) => {
        param.value = props.params.type;
        cb(param);
    });

    onMounted(() => {
        param.value = route.params.type;
        cb(param);
    });

    return param;
}
